﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Krile.Kernel;

namespace Yukkrile
{
    public partial class ConfigPage : Krile.Kernel.Control.ConfigPage
    {
        public ConfigPage()
        {
            InitializeComponent();
        }

        const string SimpleReplaceFile = "smplrep.txt";
        const string ComplexReplaceFile = "cplxrep.txt";
        private void ConfigPage_Load(object sender, EventArgs e)
        {
            using (StreamReader sr = new StreamReader(Path.Combine(Bridge.Config.PluginPath, SimpleReplaceFile)))
            {
                SimpleReplaceTable.Text = sr.ReadToEnd();
            }
            using (StreamReader sr = new StreamReader(Path.Combine(Bridge.Config.PluginPath, ComplexReplaceFile)))
            {
                ComplexReplaceTable.Text = sr.ReadToEnd();
            }
            AutoRead.Checked = Core.Config.AutoRead;
            SpeedRatio.Value = Core.Config.SpeedRatio;
        }

        public override void Apply()
        {
            using (StreamWriter sw = new StreamWriter(Path.Combine(Application.StartupPath, SimpleReplaceFile)))
            {
                sw.Write(SimpleReplaceTable.Text);
            }
            using (StreamWriter sw = new StreamWriter(Path.Combine(Application.StartupPath, ComplexReplaceFile)))
            {
                sw.Write(ComplexReplaceTable.Text);
            }
            Core.Config.AutoRead = AutoRead.Checked;
            Core.Config.SpeedRatio = (int)SpeedRatio.Value;
            Core.SendMessage(Yukkrile.TalkRequestInfo.TableReloadString);
        }
    }
}
